<html>
<head><meta charset="utf-8"><title>Cross compiling aarch64 musl · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html">Cross compiling aarch64 musl</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246924452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246924452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246924452">(Jul 23 2021 at 01:34)</a>:</h4>
<p>I'm trying to compile a "hello world" app for <code>aarch64-unknown-linux-musl</code> on Fedora.</p>
<p>My Cargo.toml</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[package]</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"hi-wo"</span>
<span class="n">version</span> <span class="o">=</span> <span class="s">"0.1.0"</span>
<span class="n">edition</span> <span class="o">=</span> <span class="s">"2018"</span>

<span class="k">[target.aarch64-unknown-linux-musl]</span>
<span class="n">linker</span> <span class="o">=</span> <span class="s">"musl-gcc"</span>
</code></pre></div>
<p>My build cmd</p>
<div class="codehilite" data-code-language="Bash"><pre><span></span><code>cargo build --target<span class="o">=</span>aarch64-unknown-linux-musl
</code></pre></div>
<p>This gives me</p>
<div class="codehilite"><pre><span></span><code>error: linking with `cc` failed: exit code: 1
...
note: /usr/bin/ld: /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status
</code></pre></div>
<p>I don't know much about linking, so I'm not really sure what I'm doing...</p>



<a name="246925212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246925212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246925212">(Jul 23 2021 at 01:49)</a>:</h4>
<p>I don't think you want to link with <code>musl-gcc</code>. That's typically a GCC for your host system. Are you building on an aarch64 platform?</p>



<a name="246925225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246925225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246925225">(Jul 23 2021 at 01:49)</a>:</h4>
<p>If you have or can install an <code>aarch64-linux-musl-gcc</code>, you might want to try linking with that.</p>



<a name="246925472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246925472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246925472">(Jul 23 2021 at 01:52)</a>:</h4>
<p>I'm building on x86. I will try to find a way to get <code>aarch64-linux-musl-gcc</code>.</p>



<a name="246926694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246926694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246926694">(Jul 23 2021 at 02:11)</a>:</h4>
<p>Well here's some other data. The <a href="https://wiki.musl-libc.org/getting-started.html">musl docs</a> say to use a cross compiler from <a href="https://musl.cc">musl.cc</a>.</p>



<a name="246928444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246928444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246928444">(Jul 23 2021 at 02:33)</a>:</h4>
<p>Okay. The musl cross compiler got me a working <code>aarch64-linux-musl-gcc</code>. However I'm still getting that same error, which makes me think that cargo isn't actually calling the bin that I think it should be. Could the <code>error: linking with `cc` failed</code> indicate a problem? Shouldn't that be <code>error: linking with `aarch64-linux-musl-gcc` failed</code>?</p>



<a name="246929629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246929629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246929629">(Jul 23 2021 at 02:54)</a>:</h4>
<p>And after much ado <span aria-label="drum" class="emoji emoji-1f941" role="img" title="drum">:drum:</span> I needed to put the <code>target.aarch64-unknown-linux-musl</code> directive in <code>.cargo/config.toml</code> and not in the manifest <span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>
<p>Well I at least I learned a little about musl.</p>



<a name="246929721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246929721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246929721">(Jul 23 2021 at 02:56)</a>:</h4>
<p>Thanks for you help Josh. That would have taken much longer if I had to putz around with <code>musl-gcc</code> before I figured out it was the wrong tool.</p>



<a name="246932133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/246932133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ben Little <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#246932133">(Jul 23 2021 at 03:45)</a>:</h4>
<p>And one (maybe) last comment. It looks like <code>musl-gcc</code> actually _does_ work if I set my configs correctly. I believe it's a wrapper utility for musl cross compilers.</p>



<a name="247000214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/247000214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#247000214">(Jul 23 2021 at 16:32)</a>:</h4>
<p><span class="user-mention" data-user-id="428223">@Ben Little</span> Ah, I didn't catch that you said <code>Cargo.toml</code>.</p>



<a name="247000293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/247000293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#247000293">(Jul 23 2021 at 16:33)</a>:</h4>
<p>Also, that's interesting that musl-gcc works; I wouldn't have expected it to.</p>



<a name="247000369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Cross%20compiling%20aarch64%20musl/near/247000369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Cross.20compiling.20aarch64.20musl.html#247000369">(Jul 23 2021 at 16:34)</a>:</h4>
<p>Perhaps different distributions use that name for a different script.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>